package com.hongyi.demo.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.hongyi.common.framework.annotation.RepeatSubmit;
import com.hongyi.common.log.annotation.Log;
import com.hongyi.common.web.controller.BaseController;
import com.hongyi.common.framework.domain.JsonResult;
import com.hongyi.common.mybatis.page.PageData;
import com.hongyi.common.mybatis.page.PageQuery;
import com.hongyi.common.log.enums.BusinessType;
import com.hongyi.demo.domain.dto.CeshiTableDto;
import com.hongyi.demo.domain.vo.CeshiTableVo;
import com.hongyi.demo.service.ICeshiTableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.validation.annotation.Validated;
import com.hongyi.common.framework.validate.AddGroup;
import com.hongyi.common.framework.validate.EditGroup;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import com.hongyi.common.framework.utils.common.CollectionUtils;

/**
 * 单表数据展示Controller
 *
 * @author DingHao
 * @date 2025-01-15 20:36:46
 */
@ApiSort(value = 262)
@Api(tags = "单表数据展示控制器")
@RestController
@RequestMapping("/demo/table")
public class CeshiTableController extends BaseController {

    @Autowired
    ICeshiTableService ceshiTableService;

    /**
     * 查询单表数据展示分页列表
     * @param ceshiTableDto 单表数据展示业务对象
     * @return 单表数据展示分页数据
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "查询单表数据展示分页列表")
    @ApiImplicitParam(name = "ceshiTable", value = "单表数据展示业务对象", paramType = "query", dataTypeClass = CeshiTableDto.class)
    @SaCheckPermission("demo:table:list")
    @GetMapping(value = "/list")
    public PageData<CeshiTableVo> list(CeshiTableDto ceshiTableDto, PageQuery pageQuery) {
        return ceshiTableService.queryCeshiTableVoPageList(ceshiTableDto,pageQuery);
    }

    /**
     * 获取单表数据展示详细信息
     *
     * @param id 单表数据展示主键
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "获取单表数据展示详细信息")
    @ApiImplicitParam(name = "id", value = "单表数据展示主键", paramType = "path", dataTypeClass = Long.class, required = true)
    @SaCheckPermission("demo:table:query")
    @GetMapping(value = "/{id}")
    public JsonResult<CeshiTableVo> getInfo(@PathVariable("id") Long id) {
        return JsonResult.ok(ceshiTableService.queryCeshiTableVoById(id));
    }

    /**
     * 新增单表数据展示
     *
     *  @param ceshiTableDto 单表数据展示业务对象
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增单表数据展示")
    @SaCheckPermission("demo:table:add")
    @Log(title = "新增单表数据展示", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping(value = "/add")
    public JsonResult<Void> add(@Validated(AddGroup.class) @RequestBody CeshiTableDto ceshiTableDto) {
        return toResult(ceshiTableService.addCeshiTable(ceshiTableDto));
    }

    /**
     * 修改单表数据展示
     *
     * @param  ceshiTableDto 单表数据展示业务对象
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "修改单表数据展示")
    @SaCheckPermission("demo:table:edit")
    @Log(title = "修改单表数据展示", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/edit")
    public JsonResult<Void> edit(@Validated(EditGroup.class) @RequestBody CeshiTableDto ceshiTableDto) {
        return toResult(ceshiTableService.editCeshiTable(ceshiTableDto));
    }

    /**
     * 删除单表数据展示
     *
     * @param ids
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "删除单表数据展示")
    @ApiImplicitParam(name = "ids", value = "单表数据展示主键数组", paramType = "path", dataTypeClass = Long.class, allowMultiple = true, required = true)
    @SaCheckPermission("demo:table:remove")
    @Log(title = "删除单表数据展示", businessType = BusinessType.DELETE)
    @DeleteMapping(value = "/{ids}")
    public JsonResult<Void> remove(@PathVariable Long[] ids) {
        return toResult(ceshiTableService.removeCeshiTableByIds(CollectionUtils.newArrayList(ids)));
    }

}
